﻿using System;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Controls.Theming;
namespace QDP.Platform.Loader
{
    public class ThemeAssemblyParser : IParser
    {
        public void Parse(string file,Stream stream)
        {
            try
            {
                D.Debug("主题程序集");
                StreamReader r = new StreamReader(stream);
                Assembly assembly = new AssemblyPart().Load(stream);
                foreach (var theme in assembly.GetTypes())
                {
                    if (theme.BaseType == typeof(Theme))
                    {
                        (App.Current as App).SetTheme(Activator.CreateInstance(theme) as Theme);//SetTheme
                    }
                }
            }
            catch (Exception ex)
            {
                D.Debug("err:"+ex.Message+" file:"+file);
#if DEBUG
                MessageBox.Show(file+"\r\n"+ex.Message);
#endif
            }
            finally { }
        }
    }
}